package days32.title219;

import java.util.HashMap;

class Solution {
    public boolean containsNearbyDuplicate(int[] nums, int k) {
        HashMap<Integer, Integer> valueAndIndexMap = new HashMap<>();
        for (int i = 0; i < nums.length; i++) {
            if (valueAndIndexMap.containsKey(nums[i])&& Math.abs(i-valueAndIndexMap.get(nums[i]))<=k)
                return true;
            valueAndIndexMap.put(nums[i],i);
        }
        return false;
    }
}